/*
 * MainApplication.h
 *
 *  Created on: Mar 29, 2017
 *      Author: zhangjf
 */

#ifndef SRC_MAINAPPLICATION_H_
#define SRC_MAINAPPLICATION_H_

#include <Poco/Logger.h>
#include <Poco/JSON/Object.h>
#include <Poco/Util/Application.h>

using namespace Poco;
using namespace Poco::Util;
using namespace Poco::JSON;

#include "JsonrpcProcessor.h"

using namespace util;

extern Logger *pLogger;

class MainApplication : public Application
{
public:
	MainApplication();
	virtual ~MainApplication();

	int main(const std::vector<std::string>& args);

	void initialize(Application& app);

private:
	bool readRequest(std::string& strReq, Object& joResp);

	void initLogger(const std::string& strLogName);

	bool initRequest(Object::Ptr& joReq, Object& joResp);
	bool prepareRequest(Object::Ptr& joReq, Object& joResp, std::string& method, std::string& sid, Object::Ptr& joParams, UInt32& id);
	bool doRequest(std::string& method, std::string& sid, Object::Ptr& joParams, Object& joResp);

	bool checkSid(std::string& sid, std::string& strErr);

	void onCheckParams(const void* pSender, JsonrpcParams& params);
	void onRunJsonrpcMethod(const void* pSender, JsonrpcParams& params);
};

#endif /* SRC_MAINAPPLICATION_H_ */
